package missPuff.com;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.com.SeasonInfo;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class VideoGalleryAdapter extends BaseAdapter{

	private Map<Integer, View> rowViews = new HashMap<Integer, View>();
	private List<SeasonInfo> list;
	private Context context;
	private File file;
	
	
	public VideoGalleryAdapter(Context context, List<SeasonInfo> seasonInfos){
		this.context = context;
		this.list = seasonInfos;
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View rowView = rowViews.get(position);
		if(rowView == null){
			LayoutInflater layoutInflater = LayoutInflater.from(context);
			rowView = layoutInflater.inflate(R.layout.videogallery_item, null);
			ImageView season_image = (ImageView) rowView.findViewById(R.id.season_image);

			file = new File(list.get(position).getPic_localUrl());
			
			if(file.exists()){
				season_image.setImageBitmap(BitmapFactory.decodeFile(list.get(position).getPic_localUrl()));
			}
			else{
				season_image.setImageResource(R.drawable.homepic_bg);
			}
		}
		
		return rowView;
	}

}
